package com.aigc.sclassroom.service.impl;

import com.aigc.sclassroom.mapper.UserMapper;
import com.aigc.sclassroom.pojo.SysUser;
import com.aigc.sclassroom.service.UserService;
import com.aigc.sclassroom.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public SysUser findByUserName(String userName) {
        SysUser user=userMapper.findByUserName(userName);
        return user;
    }

    @Override
    public void register(String userName, String password) {
        String encodePassword = SecurityUtils.encryptPassword(password);
        userMapper.add(userName,encodePassword);
    }

    @Override
    public void registerRole(Long userId, Long roleId) {
        userMapper.addUserRole(userId,roleId);
    }

    @Override
    public SysUser getUserNameById(Long userId) {
        return userMapper.getUserNameById(userId);
    }

}
